package com.kws.merchant.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kws.merchant.domain.Device;
import com.kws.merchant.domain.Item;
import com.kws.merchant.domain.po.DevicePo;
import com.kws.merchant.domain.po.RemarkPage;
import com.kws.merchant.domain.po.RemarkPo;
import com.kws.merchant.domain.po.StatusCheck;
import com.kws.merchant.domain.vo.DeviceVo;
import com.kws.merchant.service.DeviceRemarkService;
import com.kws.merchant.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.kws.common.core.domain.R;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品-设备(Device)表控制层
 *
 * @author yxy
 * @since 2024-10-22 11:09:09
 */
@RestController
@Api(tags = "设备(Device)")
@RequestMapping("device")
public class DeviceController {
    /**
     * 服务对象
     */
    @Resource
    private DeviceService deviceService;
    @Autowired
    private DeviceRemarkService deviceRemarkService;

    @PostMapping("/page")
    @ApiOperation(value = "分页查询列表")
    public R<Page<Device>> pageList(@RequestBody DevicePo devicePo){
        return R.ok(deviceService.pageList(devicePo));
    }

    @GetMapping("/detailById/{id}")
    @ApiOperation(value = "设备详情")
    public R<DeviceVo> detailById(@PathVariable Long id) {
        return R.ok(deviceService.detailById(id));
    }


    @PostMapping("/addaddDevice")
    @ApiOperation(value = "新增设备")
    public R addDevice(@RequestBody Device device) {
        return R.ok(deviceService.addDevice(device));
    }

    @PostMapping("/updateDevice")
    @ApiOperation(value = "修改设备数据")
    public R updateDevice(@RequestBody Device device) {
        return R.ok(deviceService.updateDevice(device));
    }


    @PostMapping("/delete")
    @ApiOperation(value = "删除设备-可删除多个")
    public R removeByIdList(@RequestBody List<Long> idList) {
        return R.ok(deviceService.removeByIdList(idList));
    }


    @PostMapping("/updateStatus")
    @ApiOperation(value = "设备上下架")
    public R updateStatus(@RequestBody StatusCheck statusCheck) {
        return R.ok(deviceService.updateStatus(statusCheck));
    }

    @PostMapping("deviceRemark")
    @ApiOperation("新增设备评论")
    public R deviceRemark(@RequestBody RemarkPo remarkPo ){
        return R.ok(deviceService.deviceRemark(remarkPo));
    }


    @PostMapping("/repealCheck/{id}")
    @ApiOperation(value = "撤销审核")
    public R repealCheck(@PathVariable Long id) {
        return R.ok(deviceService.repealCheck(id));
    }

    @PostMapping("remarkPage")
    @ApiOperation(value = "评论分页")
    public R remarkPage(@RequestBody RemarkPage remarkPage){
        return R.ok(deviceRemarkService.pageList(remarkPage));
    }

    @GetMapping("/listByMerchant")
    @ApiOperation(value = "商家设备列表")
    public R<List<Device>> listByMerchant() {
        return R.ok(deviceService.listByMerchant());
    }
}
